package cz.muni.fi.pa165.soccergamesarchive.persistencelayer.daos;

import cz.muni.fi.pa165.soccergamesarchive.businesslayer.dtos.TeamStatisticsDTO;
import cz.muni.fi.pa165.soccergamesarchive.persistencelayer.entities.Team;
import java.util.List;
import java.util.Map;
import javax.ejb.Local;

/**
 *
 * @author Martin Fabian
 */
@Local
public interface TeamDAO {

    /**
     * Method addTeam adds team into the database.
     *
     * @param team the team to be added
     *
     * @throws IllegalArgumentException if team do not exist or has incorrect
     * @return team saved to database record
     */
    public Team addTeam(Team team) throws RuntimeException;

    /**
     * Method changeTeam, changes team in database
     *
     * @param team the the team to be changed, instace of team must have set id
     *
     * @return changed team
     *
     * @throws IllegalArgumentException if team do not exist, has not id or has
     *                                  incorrect record
     */
    public Team changeTeam(Team team) throws RuntimeException;

    /**
     * Method removeTeam, removes team from database
     *
     * @param team, the team to be removed, instance must have set id
     *
     * @throws IllegalArgumentException if team do not exist or has not id
     */
    public void removeTeam(Team team) throws RuntimeException;

    /**
     * Method returns List of all teams in database
     *
     * @return list of all teams in database, if no team was found then returns
     *         empty list
     */
    public List<Team> getAllTeams();

    /**
     * Method getLimitedNumberOfTeams returns list of teams in given interval.
     *
     * @param offset    index of first record
     * @param limit     number of retrieved records
     * @param filterMap filter policy for current data retrieval,
     *                  Map<x,y> x is name of property(parameter)
     *                  y is pattern of property(just from beginning)
     * @param orderMap  order policy for current data retrieval
     *                  Map<x,y> x is name of property according which is result ordered
     *                  y is boolean value, if true then ordered by increase manner or
     *                  false-decrease
     *
     * @return list of teams in certain interval with applied policies. Distinct
     *         intervals will
     *         contain distinct teams. List will have the size of number of teams in
     *         given interval. If there are no teams in given interval, size of list
     *         will be 0.
     *
     * @throws IllegalArgumentException if from or to has incorrect value
     */
    public List<Team> getLimitedNumberOfTeams(int offset, int limit,
                                              Map<String, Object> filterMap,
                                              Map<String, Boolean> orderMap)
            throws RuntimeException;

    /**
     * Method apply the filter policy to all teams and then return a number of
     * corresponding teams
     *
     * @param filterMap filter policy for current action
     *
     * @return count of teams corresponding to the current filter policy
     *
     * @throws RuntimeException not possible to execute this action
     */
    public int getFilteredTeamsCount(Map<String, Object> filterMap) throws
            RuntimeException;

    /**
     * Method getTeamById returns team by id
     *
     * @param teamId is ID of team in database
     *
     * @return team that match teamId, null if none was found
     *
     * @throws IllegalArgumentException if teamId has incorrect value
     */
    public Team getTeamById(Long teamId) throws RuntimeException;

    /**
     * Method findTeam finds teams according match in name or managerName
     *
     * @param searchString the query string
     *
     * @return list of found teams
     *
     * @throws IllegalArgumentException if searchString was not specified
     */
    public List<Team> findTeam(String searchString) throws RuntimeException;

    /**
     * @param team is team of which avaliable shirt numbers want to know
     *
     * @return free dress numbers, max number is 99
     *
     * @throws IllegalArgumentException if team do not exist or has not id
     */
    public List<Integer> getAvaliableShirtNumbers(Team team) throws
            RuntimeException;

    /**
     *
     * @param team team of which statistics want to know
     *
     * @return statistics (wins, drawns, losts, goals scored and conceded) of
     *         team
     *
     * @throws IllegalArgumentException if team does not exist or has not id
     */
    public List<TeamStatisticsDTO> getTeamStatistics(Team team) throws
            RuntimeException;

}
